//===============================================================================
// Microsoft patterns & practices
// Web Client Software Factory
//-------------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//-------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================
using System.Collections.Generic;
using System.ComponentModel;
using System.Workflow.Activities;
using System.Workflow.ComponentModel;
using System;
using System.Workflow.ComponentModel.Compiler;

namespace WCSFContrib.PageFlow.WorkflowFoundation.Activities
{
	/// <summary>
	/// A custom <see cref="StateMachineWorkflowActivity"></see> for designing PageFlow based workflows.
	/// </summary>
    [ActivityValidator(typeof(PageFlowActivityValidator))]
	public partial class PageFlow : StateMachineWorkflowActivity
	{
		private Dictionary<string, object> _userDataStore;

		/// <summary>
		/// The <see cref="DependencyProperty">DependencyProperty</see> that determines if the 
		/// PageFlow is Constrained. 
		/// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2211:NonConstantFieldsShouldNotBeVisible", Justification = "Required by WF")]
        public static DependencyProperty ConstrainedProperty =
			DependencyProperty.Register("Constrained", typeof (bool), typeof (PageFlow));

		/// <summary>
		/// The <see cref="DependencyProperty">DependencyProperty</see> that determines if the 
		/// PageFlow is can be abandoned. 
		/// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2211:NonConstantFieldsShouldNotBeVisible", Justification = "Required by WF")]
        public static DependencyProperty AbandonableProperty =
			DependencyProperty.Register("Abandonable", typeof (AbandonBehavior), typeof (PageFlow));

		/// <summary>
		/// The <see cref="DependencyProperty">DependencyProperty</see> that determines the 
		/// URL to go to when the PageFlow is aborted.
		/// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2211:NonConstantFieldsShouldNotBeVisible", Justification = "Required by WF")]
        public static DependencyProperty AbortUrlProperty =
			DependencyProperty.Register("AbortUrl", typeof (string), typeof (PageFlow));

		/// <summary>
		/// The <see cref="DependencyProperty">DependencyProperty</see> that determines the
		/// URL to send users to when they attempt to visit a page that is part of the 
		/// PageFlow when there is no running instance of the PageFlow.
		/// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2211:NonConstantFieldsShouldNotBeVisible", Justification="Required by WF")]
		public static DependencyProperty NotRunningUrlProperty =
			DependencyProperty.Register("NotRunningUrl", typeof (string), typeof (PageFlow));

		/// <summary>
		/// Gets or sets whether the PageFlow is constrained.
		/// </summary>
		/// <remarks>
		/// When set to true, the PageFlow only allows pre-defined page transitions, 
		/// and will not allow transitions that are not defined in the PageFlow.
		/// When set to false, the PageFlow will allow transitions between all states
		/// in the PageFlow to all other states.
		/// </remarks>
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public bool Constrained
		{
			get { return ((bool) (base.GetValue(ConstrainedProperty))); }
			set { base.SetValue(ConstrainedProperty, value); }
		}

		/// <summary>
		/// Gets or sets the behavior for the PageFlow when a user attempts to 
		/// abandon it.
		/// </summary>
		/// <remarks>
		/// Prevent pageflows will redirect the user to the appropriate page in the pageflow even if he requests a different page in the site.
		/// AllowAndSaveInstance pageflows will allow the user to move out from the pageflow and reuse it later. 
		/// AllowAndDiscardInstance pageflows will allow the user to move out from the pageflow and will remove it so it won't be reusable.
		/// </remarks>
		[Editor()]
		[
			Description(
                "Prevent pageflows will redirect the user to the appropriate page in the pageflow even if he requests a different page in the site. " + 
				"AllowAndSaveInstance pageflows will allow the user to move out from the pageflow and reuse it later. " + 
                "AllowAndDiscardInstance pageflows will allow the user to move out from the pageflow and will remove it so it won't be reusable."
                )]
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public AbandonBehavior Abandonable
		{
            get { return ((AbandonBehavior)(base.GetValue(AbandonableProperty))); }
			set { base.SetValue(AbandonableProperty, value); }
		}

		/// <summary>
		/// Gets or sets the URL for the user to be redirected to when there are no
		/// currently running instances
		/// </summary>
		/// <remarks>
		/// Do not set this property to a page in the middle of a PageFlow.  
		/// </remarks>
		[Editor()]
		[Description("")]
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings")]
		public string NotRunningUrl
		{
			get { return ((string) (base.GetValue(NotRunningUrlProperty))); }
			set { base.SetValue(NotRunningUrlProperty, value); }
		}

		/// <summary>
		/// Gets or sets the URL to visit when a PageFlow is aborted.
		/// </summary>
		[Editor()]
		[Description("")]
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings")]
		public string AbortUrl
		{
			get { return ((string) (base.GetValue(AbortUrlProperty))); }
			set { base.SetValue(AbortUrlProperty, value); }
		}

		/// <summary>
		/// User data that is can be passed between states (or pages) in the PageFlow.
		/// </summary>
		public Dictionary<string, object> UserDataStore
		{
			get
			{
				if (_userDataStore == null)
				{
					_userDataStore = new Dictionary<string, object>();
				}
				return _userDataStore;
			}
		}
	}
}
